//get state-level enrollment weighted average costs

clear all

//location
import delimited "$data/IPEDS/fa2000hd_data_stata.csv", clear
keep unitid fips sector iclevel control carnegie
save "$temp/iped_locations", replace

//enrollment
import delimited "$data/IPEDS/ef2000a_data_stata.csv", clear
keep if line == 8 //full time undergrads
gen total_enroll = efrace15 + efrace16
keep unitid total
save "$temp/iped_enrollment", replace

//institutional characteristics
import delimited "$data/IPEDS/ic2000_ay_data_stata.csv", clear
	
//tuition, books, room and board
keep unitid chg2ay3 chg3ay3 chg4ay3 chg5ay3
ren chg2 tuition_instate
ren chg3 tuition_outstate
ren chg4 books
ren chg5 roomboard
save "$temp/iped_charges", replace


//aside: proportion of students who enroll in-state
import delimited "$data/IPEDS/ef2000c_data_stata.csv", clear
ren line fips_enroll
keep unitid fips efres01
merge m:1 unitid using "$temp/iped_locations", keep(match) nogen
gen instate = (fips_enroll == fips)
drop if fips_enroll>56 | fips > 56
collapse (sum) efres01, by(instate) //85%!


//collect all the stuff
clear
use "$temp/iped_locations", clear
merge 1:1 unitid using "$temp/iped_enrollment", keep(match) nogen
merge 1:1 unitid using "$temp/iped_charges", keep(match) nogen
gen charge_instate = tuition_instate + books + roomboard
gen charge_outstate = tuition_outstate + books + roomboard
keep if sector == 1 //| sector == 2 | sector == 3 // four-year institutions
collapse (mean) charge* [fw= total_enroll], by(fips)


//merge and map
ren fips statefips
merge 1:1 statefips using "$data/Crosswalks/state_fips_crosswalk", keep(match) nogen //looks decent
maptile charge_instate, geo(state)
drop state_full state charge_outstate
//37,483

//adjustments
preserve
	use "$temp/wage_norm", clear
	su mean
	local norm `r(mean)'
restore

replace charge = charge/0.78235 //deflate by 2000 deflator
replace charge = (charge*4)/`norm' //four years of college, normalize by mean earnings
replace charge = charge/18 //18-year periods
save "$temp/state_tuition_2000", replace


****now do 2010
//location
import delimited "$data/IPEDS/hd2010_data_stata.csv", clear
keep unitid fips sector iclevel control carnegie
save "$temp/iped_locations_2010", replace

//enrollment
import delimited "$data/IPEDS/ef2010a_data_stata.csv", clear
keep if efalevel == 1 //full time undergrads
gen total_enroll = eftotlt
keep unitid total
save "$temp/iped_enrollment_2010", replace

//institutional characteristics
import delimited "$data/IPEDS/ic2010_ay_data_stata.csv", clear
	
//tuition, books, room and board
keep unitid chg2ay3 chg3ay3 chg4ay3 chg5ay3
ren chg2 tuition_instate
ren chg3 tuition_outstate
ren chg4 books
ren chg5 roomboard
save "$temp/iped_charges_2010", replace

//collect all the stuff
clear
use "$temp/iped_locations_2010", clear
merge 1:1 unitid using "$temp/iped_enrollment_2010", keep(match) nogen
merge 1:1 unitid using "$temp/iped_charges_2010", keep(match) nogen
gen charge_instate = tuition_instate + books + roomboard
gen charge_outstate = tuition_outstate + books + roomboard
keep if sector == 1 //| sector == 2 | sector == 3 // four-year institutions
collapse (mean) charge* [fw= total_enroll], by(fips)
drop charge_outstate

//adjustments
preserve
	use "$temp/wage_norm", clear
	su mean
	local norm `r(mean)'
restore

replace charge = charge/0.95705 //deflate by 2000 deflator
replace charge = (charge*4)/`norm' //four years of college, normalize by mean earnings
replace charge = charge/18 //18-year periods
save "$temp/state_tuition_2010", replace

ren fips statefips
ren charge charge_2010
merge 1:1 statefips using "$temp/state_tuition_2000", keep(match) nogen
ren charge_instate charge_2000
ren statefips stfips
save "$temp/state_tuition", replace


/*
label define label_sector 0 "Administrative unit only" 
label define label_sector 1 "Public, 4-year or above", add 
label define label_sector 2 "Private nonprofit, 4-year or above", add 
label define label_sector 3 "Private for-profit, 4-year or above", add 
label define label_sector 4 "Public, 2-year", add 
label define label_sector 5 "Private nonprofit, 2-year", add 
label define label_sector 6 "Private for-profit, 2-year", add 
label define label_sector 7 "Public, less-than-2-year", add 
label define label_sector 8 "Private nonprofit, less-than-2-year", add 
label define label_sector 9 "Private for-profit, less-than-2-year", add 
label values sector label_sector

label define label_iclevel 1 "Four or more years" 
label define label_iclevel 2 "At least 2 but less than 4 years", add 
label define label_iclevel 3 "Less than 2 years (below associate)", add 
label values iclevel label_iclevel
*/



//end of dofile